package com.template.templateuser.auth.serviceauth.config;

import com.template.templateuser.domain.dto.SysUserDTO;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.io.Serializable;
import java.util.Collection;
import java.util.List;

public class TeamplateUserDetails implements UserDetails, Serializable {



    private SysUserDTO user;
    private Collection<? extends GrantedAuthority> authorities;

    public TeamplateUserDetails(SysUserDTO user, List<GrantedAuthority> authorities) {
        this.user = user;
        this.authorities = authorities;
    }

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return authorities;
    }

    @Override
    public String getPassword() {
        if(user!=null){
            return user.getPassword();
        }
        return null;
    }

    @Override
    public String getUsername() {
        if(user!=null){
            return user.getLoginName();
        }
        return null;
    }

    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @Override
    public boolean isEnabled() {
        return true;
    }
    public SysUserDTO getUser() {
        if(user != null)
            return user;
        return null;
    }
}
